package com.newcapec.modules.terminal.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.newcapec.common.utils.R;
import com.newcapec.modules.health.entity.CustomerEntity;
import com.newcapec.modules.health.service.CustomerService;
import com.newcapec.modules.pass.entity.GateInfoEntity;
import com.newcapec.modules.pass.entity.VenueInfoEntity;
import com.newcapec.modules.pass.service.GateInfoService;
import com.newcapec.modules.pass.service.VenueInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author steven
 * @email wangsen127@163.com
 * @date 2021-12-29 10:54:16
 */
@RestController
@RequestMapping("terminal/machine")
public class MachineController {
    @Autowired
    private CustomerService customerService;
    @Autowired
    private VenueInfoService venueInfoService;
    @Autowired
    private GateInfoService gateInfoService;

    /**
     * 学校列表
     */
    @GetMapping("/listCustomer")
    public R listCustomer(){
        List<CustomerEntity> list = customerService.list();

        return R.ok().put("list", list);
    }

    /**
     * 场馆列表
     */
    @GetMapping("/listVenue")
    public R listVenue(@RequestParam Map<String, Object> params){
        Object customerId = params.get("customerId");
        QueryWrapper<VenueInfoEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(customerId!=null, "customer_id", customerId);
        List<VenueInfoEntity> list = venueInfoService.list(queryWrapper);

        return R.ok().put("list", list);
    }

    /**
     * 出入口列表
     */
    @GetMapping("/listGate")
    public R listGate(@RequestParam Map<String, Object> params){
        Object venueId = params.get("venueId");
        QueryWrapper<GateInfoEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(venueId!=null, "venue_id", venueId);
        List<GateInfoEntity> list = gateInfoService.list(queryWrapper);

        return R.ok().put("list", list);
    }
}
